package com.qf.config;

import com.qf.api.CacheFeign;
import com.qf.constant.RabbitMQConstants;
import com.qf.netty4.NettyClient;
import com.qf.thread.SendReportThread;
import com.qf.thread.SendSubmitRespThread;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class NettyConfig {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    @Autowired
    private CacheFeign cacheFeign;

    //ip
    @Value("${cmpp.host}")
    public String host;

    //端口
    @Value("${cmpp.port}")
    public int port;

    //账号
    @Value("${cmpp.serviceId}")
    public String serviceId;

    //密码
    @Value("${cmpp.pwd}")
    public String pwd;


    @Bean(initMethod = "start")
    public NettyClient nettyClient(){
        NettyClient cmppClient= new NettyClient(host,port,serviceId,pwd);
        cmppClient.start();
        return cmppClient;
    }

    @Bean
    public SendReportThread sendReportThread() {
        SendReportThread sendReportThread= new SendReportThread(RabbitMQConstants.TOPIC_PUSH_SMS_REPORT
                ,RabbitMQConstants.TOPIC_UPDATE_SMS_REPORT,rabbitTemplate, cacheFeign);
        new Thread(sendReportThread).start();
        return sendReportThread;
    }

    @Bean
    public SendSubmitRespThread sendSubmitRespThread() {
        SendSubmitRespThread sendSubmitRespThread= new SendSubmitRespThread(RabbitMQConstants.TOPIC_SMS_SEND_LOG
                ,rabbitTemplate);
        new Thread(sendSubmitRespThread).start();
        return sendSubmitRespThread;
    }
}
